import request from '@/utils/request'
const api_name = '/user';

export default {
  // 通过id获取用户
  getUserById(id) {
    return request({
      url: `${api_name}/${id}`,
      method: 'get'
    });
  },
  // 根据条件查询用户(分页)
  getUserListByPage(page, limit, searchObj) {
    return request({
      url: `${api_name}/${page}/${limit}`,
      method: 'post',
      data: searchObj
    });
  },
  // 根据ID删除一个用户
  removeUserById(id) {
    return request({
      url: `${api_name}/${id}`,
      method: 'delete'
    });
  },
  // 新增一个用户
  saveUser(user) {
    return request({
      url: `${api_name}/`,
      method: 'post',
      data: user
    });
  },
  // 修改一个用户
  updateUser(user) {
    return request({
      url: `${api_name}/${user.userId}`,
      method: 'put',
      data: user
    });
  }
};

export function login(data) {
  return request({
    url: `${api_name}/admin/login`,
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: `${api_name}/info`,
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: `${api_name}/logout`,
    method: 'post'
  })
}